<?php
class Control_Gm_serverStatus {
	function serverStatus() {
		$action = MooForm::request('action');
		$nowGame = $game 	= MooForm::request('game');
		$platform = MooForm::request('platform');
		$game = MooObj::get('Game')->transportGame($game);
		// 设置起止时间
		if($action == 0) {
			MooView::render('serverStatus');
		} else {
			$platformInfo = MooObj::get('Game')->getPlatformInfoByGame($game);
			if($platformInfo) {
				MooView::set('platformList', $platformInfo);
			}
			
			$serverLists = MooObj::get('Gm')->getServerListByGame($nowGame);
			
			if($platform) {
				foreach ($serverLists as $key => $val) {
					if($val['platform'] != $platform) {
						unset($serverLists[$key]);
					}
				}
			}
			// 后台用户名
			$userName = MooObj::get('User')->getUserName();
			// $params['user'] = $userName;
			
			$falseData = array(
				'curSession' => 0,
				'peakSession' => 0,
				'totalRecvBytes' => 0,
				'totalRecvProto' => 0,
				'totalSendBytes' => 0,
				'totalSendProto' => 0,
				'curRecvRate' => 0,
				'peakRecvRate' => 0,
				'peakSendRate' => 0,
				'curSendRate' => 0,
				'peakSendRate' => 0,
				'unprocessTaskCount' => 0,
				'newUser' => 0,
				'newDevice' => 0,
				'newUser' => 0,
				'rechargeUser' => 0,
				'recharge' => 0,
			);
			
			$serverStatusDatas = array();
			if($serverLists) {
				foreach ($serverLists as $key => $val) {
					$cmd = "serverstatus";
					$serverUrl = $val['url'];
// 					$serverUrl = "192.168.199.136:9001";
					$url = MooObj::get('Gm')->getUrl($serverUrl, $cmd, $userName, $params);
					
					$res = MooUtil::curl_send($url, null, 2);
					
					if($res) {
						$returnData = MooJson::decode($res, true);
						if($returnData) {
							$serverStatusDatas[$key] = $returnData;
						} else {
							$falseData['platform'] = $key;
							$serverStatusDatas[$key] = $falseData;
						}
					} else {
						$falseData['platform'] = $key;
						$serverStatusDatas[$key] = $falseData;
					}
				}
			}
			MooView::set('serverStatusDatas', $serverStatusDatas);
			MooView::set('nowGame', $nowGame);
			MooView::set('nowPlatform', $platform);
			MooView::render('serverStatus');
		}
	}
}